package com.ujiuye.utils;

import com.ujiuye.pojo.Student;

import java.util.List;

/**
 * 分页工具类
 */
public class PageTools {

    private int currentPage;//当前页
    private int pageSize;//每页显示的条数
    private int sumSize;//总条数
    private int index;//索引
    private int prePage;//上一页
    private int sumPage;//总页数
    private int nextPage;//下一页

    //用来存储对应的学生信息
    private List<Student> studentList;


    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    public PageTools(int currentPage, int pageSize, int sumSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.sumSize = sumSize;


        //上一页
        this.prePage = currentPage == 1 ? 1 : currentPage - 1;
        //索引
        this.index = (currentPage - 1) * pageSize;
        //总页数  21  5
        this.sumPage = sumSize / pageSize + (sumSize % pageSize == 0 ? 0 : 1);
        //下一页
        this.nextPage = (currentPage == sumPage ? currentPage : currentPage + 1);
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getSumSize() {
        return sumSize;
    }

    public void setSumSize(int sumSize) {
        this.sumSize = sumSize;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getSumPage() {
        return sumPage;
    }

    public void setSumPage(int sumPage) {
        this.sumPage = sumPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    @Override
    public String toString() {
        return "PageTools{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", sumSize=" + sumSize +
                ", index=" + index +
                ", prePage=" + prePage +
                ", sumPage=" + sumPage +
                ", nextPage=" + nextPage +
                '}';
    }
}
